package com.huawei;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Description: HJ52 计算字符串的编辑距离
 *
 * @author weiruibai.vendor
 * Date: 2022/8/30 14:16
 */
public class HJ52 {

    /**
     * abcdefg
     * abcdef
     *
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] str1 = "abcdefg".toCharArray();//br.readLine().toCharArray();
        char[] str2 = "abcdef".toCharArray(); //br.readLine().toCharArray();
        int N = str1.length + 1;
        int M = str2.length + 1;
        int[][] dp = new int[N][M];
        for (int i = 1; i < N; i++) {
            dp[i][0] = i * 1;
        }
        for (int i = 1; i < M; i++) {
            dp[0][i] = i * 1;
        }
        for (int i = 1; i < N; i++) {
            for (int j = 1; j < M; j++) {
                // 1
                int v1 = dp[i - 1][j - 1] + (str1[i - 1] == str2[j - 1] ? 0 : 1);
                // 2
                int v2 = dp[i - 1][j] + 1;
                // 3
                int v3 = dp[i][j - 1] + 1;
                dp[i][j] = Math.min(Math.min(v1, v2), v3);
            }
        }
        System.out.println(dp[N - 1][M - 1]);
    }
}
